<?php
/**
 * Created by PhpStorm.
 * User: sunshubo
 * Date: 2017/11/23
 * Time: 21:58
 */

class PushClassInfo_model extends MY_Model
{
    function push_class_info($body)
    {
        $body = (json_decode($body));
        $id = $body->id;
        $class = $body->class;
//        var_dump($id, $class);

        switch ($class[0]) {
            case 1:
                break;
            case 2:
                break;
            case 3:
                $query = $this->my_select('ws_class_shufa', array('studentId' => $id));
                if ($query) {//数据已存在，认为更改班级信息
                    $query = $this->my_update('ws_class_shufa', array('gradeId' => $class[1], 'classId' => $class[2]), array('studentId' => $id));
                    if ($query){
                        return json_encode(array('result' => SUCCESS, 'msg' => '班级更新成功'));
                    }else{
                        return json_encode(array('result' => ERROR, 'msg' => '班级已存在'));
                    }
                }
                $query = $this->my_insert('ws_class_shufa', array('studentId' => $id, 'gradeId' => $class[1], 'classId' => $class[2]));
                if ($query) {
                    return json_encode(array('result' => SUCCESS, 'msg' => '添加成功！'));
                }
                break;
        }
        return json_encode(array('result' => 2, 'msg' => '添加失败！'));
    }
}